home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / asm_n_z.zip / TT.ASM < prev    next >
Assembly Source File  |  1988-02-22  |  21KB  |  848 lines

  1. COMMENT * ==================================================================
  2.  
  3.     Copyright (C) 1988, George A. Stanislav.
  4.     All Rights Reserved.
  5.  
  6.     This program is a dumb terminal for FOSSIL communications.
  7.     It works only from the COM1 port and only at 300/1200/2400
  8.     baud, with a built-in ansi-bbs and AVATAR terminal emulation.
  9.     That means that if you call a BBS supporting ANSI graphics,
  10.     it should correctly recognize the movement of your cursor keys,
  11.     as well as the <home> and <end> keys. More importantly, if
  12.     the BBS sends out Opus color codes, the AVATAR emulator will
  13.     convert them to ANSI sequences. You need ANSI.SYS properly
  14.     installed for either emulation to work properly.
  15.  
  16.     The purpose of this program is mostly didactical. Lesson 2
  17.     of FOSSIL programming. (Lesson 1 was the previous version,
  18.     called DUMBTERM.) You can probably add Lesson 3 as of version
  19.     1.02, the lesson is contained in the AVATAR emulator.
  20.  
  21.     New in version 1.03 are 20 user configurable keys. With the
  22.     help of TTSETUP.COM, you can configure the 10 function keys
  23.     when combined with either <ctl> or <alt> for a string up to
  24.     32 characters long. The same program will allow you to choose
  25.     defaults other than those coded here.
  26.  
  27.     While the program is a dumb terminal, it allows you to transfer
  28.     file using the Zmodem protocol. For that, however, you need
  29.     TWO additional programs: Author's PROZ.COM and Chuck Forsberg's
  30.     DSZ.COM or DSZ.EXE. Of the two, PROZ.COM must be in the current
  31.     default directory, while DSZ can be anywhere as long as the
  32.     PATH environmental variable is pointing at it.
  33.  
  34.     You can freely copy it and give it to others. The word FREELY
  35.     is substantial. Any charge imposed in connection with passing
  36.     this program onto someone else is in direct violation with
  37.     my Copyright. That also means that anyone who sells diskettes
  38.     or other media with public domain or shareware programs is
  39.     expressly prohibited from distributing this program. This program
  40.     is NOT in public domain!
  41.  
  42.     Usage:
  43.  
  44.         As it is a very simple terminal indeed, all you need is
  45.         a 300, 1200, or 2400 baud modem attached to COM1 and
  46.         type TT.
  47.  
  48.         Whatever you type thereafter goes directly into the
  49.         modem. To dial a number you will have to type
  50.         ATDT 123-4567 <cr>. To initialize the modem, you
  51.         will have to type ATZ or whatever your modem manual
  52.         suggests.
  53.  
  54.         To exit the program, type ^END. That means you can use
  55.         ^C online.
  56.  
  57.     Obviously, you cannot use this program for file transfers. This
  58.     is just a dumb terminal.
  59.  
  60.     Support form author:
  61.  
  62.         None.
  63.  
  64. * ===========================================================================
  65.  
  66. ;    MACROS to make it look like a high level language
  67.  
  68. fossil    macro        ; call FOSSIL driver
  69.  
  70.     int    14h
  71.  
  72. endm
  73.  
  74. dos    macro        ; call MS DOS
  75.  
  76.     int    21h
  77.  
  78. endm
  79.  
  80. print    macro    text
  81.  
  82.     mov    ah,09h    ; display string
  83.     ifnb    <text>
  84.       mov    dx,offset text    ; point to it
  85.     endif
  86.     dos
  87.  
  88. endm
  89.  
  90. exit    macro    level
  91.  
  92.     mov    ax,4c00h + level    ; ah = 4ch, al = level
  93.     dos
  94.  
  95. endm
  96.  
  97. port    macro        ; choose COM1
  98.  
  99.     mov    dx,cport    ; dx = cport
  100.     fossil        ; call the driver
  101.  
  102. endm
  103.  
  104. setB    macro    rate    ; set baud rate
  105.  
  106.     ifnb    <rate>
  107.       mov    al,baud    ; that's ah = 0, al = 10000011 initially
  108.     endif
  109.     xor    ah,ah
  110.         port        ; COM1
  111.  
  112. endm
  113.  
  114. csend    macro        ; transmit a character from al
  115.  
  116.     mov    ah,1    ; the character must already be in al
  117.     port
  118.  
  119. endm
  120.  
  121. crec    macro        ; receive a character from fossil buffer
  122.  
  123.     mov    ah,2    ; the received character will be in al
  124.     port
  125.  
  126. endm
  127.  
  128. open    macro
  129.     local opened,oldfos,done
  130.  
  131.     mov    ah,4    ; initialize fossil
  132.     port
  133.     cmp    ax,1954h    ; the fossil "magic" number
  134.     je    opened    ; achieved
  135.     print    msg    ; fossil not present
  136.     exit    1    ; abort with errorlevel 1
  137. opened:    cmp    bh,4    ; need at least FOSSIL, rev. 4
  138.     jb    oldfos
  139.     cmp    bl,19h    ; can we write a block?
  140.     jnb    done    ; yes, done
  141. oldfos:    add    oldrev,bh ; fix error message
  142.     print    neednew    ; print error message
  143.     exit    2    ; abort with errorlevel 2
  144. done:    
  145.  
  146. endm
  147.  
  148. close    macro        ; cleanup
  149.  
  150.     mov    ah,5
  151.     port
  152.  
  153. endm
  154.  
  155. dtr    macro    onoroff
  156.  
  157.     mov    ax,600h + onoroff    ; on = 1, off = 0
  158.     port
  159.  
  160. endm
  161.  
  162. finkey    macro        ; fossil "inkey"
  163.  
  164.     mov    ah,0ch
  165.     port
  166.     inc    ax    ; zero flag = 0 if nothing there
  167.  
  168. endm
  169.  
  170. inkey    macro        ; keyboard "inkey"
  171.  
  172.     mov    ah,0dh
  173.     fossil        ; never mind the port
  174.     inc    ax    ; check zero flag
  175.  
  176. endm
  177.  
  178. cget    macro        ; read character from keyboard
  179.  
  180.     mov    ah,0eh
  181.     fossil
  182.  
  183. endm
  184.  
  185. cput    macro        ; display a character
  186.  
  187.     mov    ah,13h    ; character must be in al
  188.     fossil
  189.  
  190. endm
  191.  
  192. sends    macro    string,strlen
  193.  
  194.     ifnb <string>
  195.     mov    di,offset string
  196.     mov    cx,strlen
  197.     endif
  198.     mov    ah,19h
  199.     fossil
  200.  
  201. endm
  202.  
  203. talk    macro
  204.     local talk1,talked ; talk to the other end
  205.  
  206.     inkey        ; check if the keyboard has been hit
  207.     jz    talked    ; no it was not, keep quiet
  208.     cget        ; yes, see what it is
  209.     or    al,al    ; is it a function key?
  210.     jne    talk1    ; no, send it out
  211.     call    funkey    ; process function key
  212.     jmp    short talked
  213. talk1:    csend        ; send char out
  214. talked:
  215.  
  216. endm
  217.  
  218. listen    macro
  219.     local l1,listen1,listened    ; listen to the other end
  220.  
  221.     finkey        ; anything there?
  222.     jz    listened    ; nope
  223.     crec        ; receive character
  224.     cmp    al,26    ; is it a control character?
  225.     ja    listen1    ; no, check further
  226. l1:    call    avatar    ; advanced video attribute transfer
  227.     jmp    short listened
  228. listen1:cmp    avaflag,0    ; are we processing avatar?
  229.     jne    l1    ; yes, call avatar
  230.     cput        ; no, display it
  231. listened:
  232.  
  233. endm
  234.  
  235. chat    macro
  236.     local keep
  237. keep:
  238.     talk
  239.     listen
  240.     jmp    keep
  241.  
  242. endm
  243.  
  244. sendc    macro    char
  245.  
  246.     mov    al,char
  247.     csend
  248.  
  249. endm
  250.  
  251. ; DEFINES
  252.  
  253. ctlA    equ    1
  254. ctlB    equ    2
  255. ctlC    equ    3
  256. ctlD    equ    4
  257. ctlE    equ    5
  258. ctlF    equ    6
  259. ctlG    equ    7
  260. ctlH    equ    8
  261. ctlL    equ    12
  262. ctlV    equ    22
  263. ctlY    equ    25
  264. cr    equ    13
  265. dle    equ    16
  266. lf    equ    10
  267. bell    equ    7
  268. stop    equ    '$'
  269. on    equ    1
  270. off    equ    0
  271. tab    equ    9
  272. bmask    equ    00011111b    ; baud rate mask
  273. b3    equ    01000000b    ; 300 baud mask
  274. b12    equ    10000000b    ; 1200 baud mask
  275. b24    equ    10100000b    ; 2400 baud mask
  276. pmask    equ    11100000b    ; parity etc. mask
  277. p7E1    equ    00011010b    ; mask for 7E1
  278. p8N1    equ    00000011b    ; mask for 8N1
  279. imask    equ    00001000b    ; intensity bit
  280. fgrmask    equ    00000111b    ; foreground color mask
  281. bkgmask    equ    01110000b    ; background color
  282. black    equ    0
  283. blue    equ    1
  284. green    equ    2
  285. cyan    equ    3
  286. red    equ    4
  287. magenta    equ    5
  288. brown    equ    6
  289. white    equ    7
  290. vflag    equ    1        ; ^v received
  291. aflag    equ    2        ; ^v^a received
  292. yflag    equ    3        ; ^y received
  293. yflag2    equ    4        ; ^y received, repeat character known
  294. hflag    equ    5        ; ^v^h received
  295. hflag2    equ    6        ; ^v^h received, row known
  296. noflag    equ    0
  297.  
  298. ; The PROGRAM
  299.  
  300. dumb    segment
  301.  
  302.     assume    ds:dumb,es:dumb,cs:dumb,es:dumb
  303.  
  304.     org    100h
  305.  
  306. main    proc
  307. start:    jmp    begin
  308.  
  309. version    dw    0104h        ; 1.04
  310. cport    dw    0        ; start with COM1
  311. baud    db    10000011b    ; start with 1200 baud 8N1
  312. editor    db    0,' /C ',80 dup(0)    ; space for editor
  313. macword    label    word
  314. mac    db    20 dup (32 dup (?))    ; space for 20 key macros
  315. macount    db    20 dup (0)    ; sizes of 20 key macros
  316. copr    db    cr,lf,'TinyTerm - ANSI & AVATAR Emulating Terminal, version 1.04',cr,lf
  317.     db    'Copyright (C) 1988, George A. Stanislav',cr,lf
  318.     db    'All Rights Reserved.',cr,lf,lf
  319.     db    'This is a very simple terminal. Whatever you type '
  320.     db    '(except ^<end>) is sent',cr,lf
  321.     db    'straight to the modem. Its initial setup is 1200 baud, 8N1, from '
  322.     db    'COM1. The full',cr,lf
  323.     db    'assembly language source code is included so you can write '
  324.     db    'your own programs',cr,lf
  325.     db    'using other configurations. The goal of this program is to '
  326.     db    'show to as many',cr,lf
  327.     db    'as possible how to write FOSSIL communications programs '
  328.     db    'and AVATAR emulation.',cr,lf,lf
  329.     db    'TinyTerm allows you to configure the 10 function keys '
  330.     db    'combined with the',cr,lf
  331.     db    '<alt> or <ctl> keys as "macros". You can either define '
  332.     db    'them in the source',cr,lf
  333.     db    'code or, better yet, by running TTSETUP.COM. This also '
  334.     db    'allows you to choose',cr,lf
  335.     db    'defaults other than COM1, 1200 baud and 8N1.',cr,lf,lf
  336.     db    'Hit <F10> for help, <Ctrl> <End> to exit.',cr,lf,lf,stop
  337. msg    db    'FOSSIL not found. In order to run this program you need to '
  338.     db    'load a FOSSIL',cr,lf
  339.     db    'communications driver before you call TINYTERM.',cr,lf,stop
  340. neednew    db    cr,lf,lf,'You are using revision '
  341. oldrev    db    '0 of FOSSIL. For T